<?php
/*
  $Program: ECJC Online Shop
  $Id: packingslip.php
  $Based on: osCommerce, Open Source E-Commerce Solutions
  Released under the GNU General Public License
*/
  defined( 'JOSCOM_VERSION' ) or die( 'Direct Access to this location is not allowed.' );
  if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' )
  | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_banners' ))) {
    //j15nc
  }
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      tep_db_connect() or die('Unable to connect to database server!');
    }
    global $category_links, $languages_id, $cPath, $cPath_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    require(DIR_WS_COMPONENT . 'includes/application_top.php');
  }
  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  $oID = tep_db_prepare_input($_REQUEST['oID']);
  $orders_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '" . (int)$oID . "'");

  include(DIR_WS_CLASSES . 'order.php');
  $order = new order($oID);
?>

<link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_COMPONENT ?>includes/stylesheet.css">

<!-- body_text //-->
<table border="0" width="100%" cellspacing="0" cellpadding="2">
  <tr>
    <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td class="pageHeading"><?php echo nl2br(STORE_NAME_ADDRESS); ?></td>
        <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'oscommerce.gif', 'osCommerce', '204', '50'); ?></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
      <tr>
        <td colspan="2"><?php echo tep_draw_separator(); ?></td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="maincol"><b><?php echo ENTRY_SOLD_TO; ?></b></td>
          </tr>
          <tr>
            <td class="maincol"><?php echo tep_address_format($order->customer['format_id'], $order->billing, 1, '', '<br>'); ?></td>
          </tr>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
          </tr>
          <tr>
            <td class="maincol"><?php echo $order->customer['telephone']; ?></td>
          </tr>
          <tr>
            <td class="maincol"><?php echo '<a href="mailto:' . $order->customer['email_address'] . '"><u>' . $order->customer['email_address'] . '</u></a>'; ?></td>
          </tr>
        </table></td>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="maincol"><b><?php echo ENTRY_SHIP_TO; ?></b></td>
          </tr>
          <tr>
            <td class="maincol"><?php echo tep_address_format($order->delivery['format_id'], $order->delivery, 1, '', '<br>'); ?></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  </tr>
  <tr>
    <td><table border="0" cellspacing="0" cellpadding="2">
      <tr>
        <td class="maincol"><b><?php echo ENTRY_PAYMENT_METHOD; ?></b></td>
        <td class="maincol"><?php echo $order->info['payment_method']; ?></td>
      </tr>
    </table></td>
  </tr>
<?php //MVS start

    $index = 0;
      $order_packslip_query = tep_db_query("select vendors_id, 

orders_products_id, products_name, products_model, products_price, 

products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS 

. " where orders_id = '" . (int)$oID . "'");
      while ($order_packslip_data = 

tep_db_fetch_array($order_packslip_query)) {
      $packslip_products[$index] = array('qty' => 

$order_packslip_data['products_quantity'],
                                        'name' => 

$order_packslip_data['products_name'],
                                        'model' => 

$order_packslip_data['products_model'],
                                        'tax' => 

$order_packslip_data['products_tax'],
                                        'price' => 

$order_packslip_data['products_price'],
                                        'final_price' => 

$order_packslip_data['final_price']);

        $subindex = 0;
        $packslip_attributes_query = tep_db_query("select products_options, 

products_options_values, options_values_price, price_prefix from " . 

TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$oID . "' 

and orders_products_id = '" . 

(int)$order_packslip_data['orders_products_id'] . "'");
        if (tep_db_num_rows($packslip_attributes_query)) {
          while ($packslip_attributes = 

tep_db_fetch_array($packslip_attributes_query)) {
            $packslip_products[$index]['packslip_attributes'][$subindex] = 

array('option' => $packslip_attributes['products_options'],
                                                                     'value' 

=> $packslip_attributes['products_options_values'],
                                                                     

'prefix' => $packslip_attributes['price_prefix'],
                                                                     'price' 

=> $packslip_attributes['options_values_price']);

            $subindex++;
          }
        }
        $index++;
      }
       ?>
  <tr>
    <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr class="dataTableHeadingRow">
        <td class="dataTableHeadingContent" colspan="2"><?php echo 

TABLE_HEADING_PRODUCTS; ?></td>
        <td class="dataTableHeadingContent"><?php echo 

TABLE_HEADING_PRODUCTS_MODEL; ?></td>
      </tr>
<?php
$package_num = sizeof($order->products);
$box_num = $l + 1;
      for ($i=0, $n=sizeof($packslip_products); $i<$n; $i++) {
      echo '      <tr class="dataTableRow">' . "\n" .
           '        <td class="dataTableContent" valign="top" align="left">' 

. $packslip_products[$i]['qty'] . '&nbsp;x&nbsp;&nbsp;' . 

$packslip_products[$i]['name'];
           if (isset($packslip_products[$i]['packslip_attributes']) && 

(sizeof($packslip_products[$i]['packslip_attributes']) > 0)) {
        for ($j=0, $k=sizeof($packslip_products[$i]['packslip_attributes']); 

$j<$k; $j++) {
          echo '<br><nobr><small>&nbsp;<i> - ' . 

$packslip_products[$i]['packslip_attributes'][$j]['option'] . ': ' . 

$packslip_products[$i]['packslip_attributes'][$j]['value'];
          echo '</i></small></nobr>';
        }
      }
           '        <td class="dataTableContent" valign="top" align="left">' 

. $packslip_products[$i]['spacer'];



      echo '        </td>' . "\n" .
           '        <td class="dataTableContent" valign="top">' . 

$packslip_products[$i]['spacer'] . '</td>' . "\n" .
           '        <td class="dataTableContent" valign="top">' . 

$packslip_products[$i]['model'] . '</td>' . "\n" .
           '      </tr>' . "\n";
    }
//MVS end

?>
    </table></td>
  </tr>
</table>
<!-- body_text_eof //-->

<?php
  require(DIR_WS_INCLUDES . 'application_bottom.php');

  // -- webMS Modification --
  // reset the Mambo Database connection (stomped by osCommerce Connection)
  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
?>
